# buildings = [[2,9,10],[3,7,15],[5,12,12],[15,20,10],[19,24,8]]
buildings=[[0,2,3],[2,5,3]]
# buildings=[[0,2147483647,2147483647]]
#方法会超时，遇到上的案例的时候
def getSkyline(buildings):
    # 先写出所有的边界点
    maxX = -1
    for i in buildings:
        if i[1] > maxX:
            maxX = i[1]
    indexHMax = [0 for _ in range(maxX + 1)]
    for i in buildings:
        for j in range(i[0], i[1] + 1):
            if indexHMax[j] < i[2]:
                indexHMax[j] = i[2]
    print(indexHMax)
    # 记录次大值
    indexHSubMax = [0 for _ in range(maxX + 1)]
    for i in buildings:
        for j in range(i[0], i[1] + 1):
            if indexHSubMax[j] < i[2] and i[2] != indexHMax[j]:
                indexHSubMax[j] = i[2]
    print(indexHSubMax)
    points = []
    for i in range(maxX):
        if i == 0 and indexHMax[i] != 0:
            points.append([i, indexHMax[i]])
        if indexHMax[i + 1] > indexHMax[i]:
            # 上升点
            points.append([i + 1, indexHMax[i + 1]])
        if indexHMax[i + 1] < indexHMax[i]:
            # 下降点
            points.append([i, indexHSubMax[i]])
    points.append([maxX, 0])
    print(points)



pointXs=[]
for i in buildings:
    pointXs.append(i[0])
    pointXs.append(i[1])
indexHMax = dict()
for i in pointXs:
    # indexHMax.append([i,0])
    indexHMax[i]=0
for i in buildings:
    for j in indexHMax:
        if j>=i[0] and j<=i[1]:
            if indexHMax[j]<i[2]:
                indexHMax[j]=i[2]
points=[]
for i in buildings:
    points.append([i[0],i[2]])
    points.append([i[1],i[2]])
# print(points)
points.sort()
indexHSubMax=dict()
for i in pointXs:
    # indexHSubMax.append([i,0])
    indexHSubMax[i]=0
for i in buildings:
    for j in indexHSubMax:
        if j>=i[0] and j<=i[1]:
            if indexHSubMax[j]<i[2] and i[2]!=indexHMax[j]:
                indexHSubMax[j]=i[2]


# print(indexHMax)
# print(indexHSubMax)

print(points)
res=[]
haveUseXIndex=-1
for i in range(len(points)):
    print(haveUseXIndex)
    if points[i][1] != haveUseXIndex and points[i][1]==indexHMax[points[i][0]]:
        # haveUseXIndex.append(points[i][1])
        haveUseXIndex=points[i][1]
        res.append(points[i])
    elif points[i][1] == haveUseXIndex and points[i][1]==indexHMax[points[i][0]]:
        #已经有这个高度的值了，同时，这个高度是该横坐标的最大值
        # haveUseXIndex.append(indexHSubMax[points[i][0]])
        for j in buildings:
            if points[i][0]>=j[0] and points[i][0]<=j[1] and j[2]==indexHMax[points[i][0]]:
                continue

        haveUseXIndex=indexHSubMax[points[i][0]]
        res.append([points[i][0],indexHSubMax[points[i][0]]])
print(res)
